package com.xiaozhou.leetCode.leetCode100;

public class LeetCode14 {
    public static String longestCommonPrefix(String[] strs) {
        if (strs.length <= 1){
            return strs[0];
        }
        int j = 0;
        String s1 = strs[0];
        while (j < s1.length()){
            for (int i = 1; i < strs.length; i++) {
                if (strs[i].length() -1 < j || s1.charAt(j) != strs[i].charAt(j)){
                    return s1.substring(0, j);
                }
            }
            j++;
        }
        return s1.substring(0, j);
    }

    public static void main(String[] args) {
        String s = longestCommonPrefix(new String[]{"flower","flow","flight"});
        System.out.println(s);
    }
}
